/**
    Copyright (C) 2012 Guido Ludwig

    This file is part of JATT.
	http://code.google.com/p/jatt/

    JATT is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.guidoludwig.jatt.util;

import java.io.File;
import java.io.FilenameFilter;

public class ArtworkFilenameFilter implements FilenameFilter {

	public static final FilenameFilter INSTANCE = new ArtworkFilenameFilter(false);
	public static final FilenameFilter INSTANCE_PREFIX = new ArtworkFilenameFilter(true);

	public static final String FOLDER_PREFIX = "folder";
	public static final String EXTENSION_PNG = "png";
	public static final String EXTENSION_JPG = "jpg";

	private static final String FOLDER_JPG = FOLDER_PREFIX + "." + EXTENSION_JPG;
	private static final String FOLDER_PNG = FOLDER_PREFIX + "." + EXTENSION_PNG;

	private final boolean byPrefix;

	private ArtworkFilenameFilter(boolean byPrefix) {
		this.byPrefix = byPrefix;
	}

	// TODO : validate by mime type
	@Override
	public boolean accept(File dir, String name) {
		if (byPrefix) {
			return name.toLowerCase().startsWith(FOLDER_PREFIX);
		}
		return name.toLowerCase().equals(FOLDER_PNG) || name
				.toLowerCase().equals(FOLDER_JPG);
	}

}